/*****************************************************
	SmileyUSART.h 3/15/08 Joe Pardue
	Device specfic USART Definitions
******************************************************/

#include <avr/io.h>
#include <avr/pgmspace.h> 
#include <avr/wdt.h>


/*****************************************************
	Remove '//' from device you are using
	Add '//' to devices you are not using
******************************************************/
#define ATmega644
//#define ATmega32
//#define Butterfly
//#define Arduino


#if defined(Butterfly)
#include <avr/interrupt.h>
#define F_CPU 8000000
#define BAUD_RATE 19200
#elif defined(Arduino) || defined(ATmega644)
#define F_CPU 16000000L
#define BAUD_RATE 57600
#endif


/*****************************************************
	From Mike Perks, a generous AVRFreak - modified quite a bit
******************************************************/
/* defines for the various USART registers */

/*#if defined(Butterfly)

   // ATMega with one USART 
   #define USART_BAUD_RATE_HIGH        	UBRR0H
   #define USART_BAUD_RATE_LOW        	UBRR0L
   #define USART_CONTROL_STATUS_REG_A	UCSR0A
   #define USART_CONTROL_STATUS_REG_B	UCSR0B
   #define USART_CONTROL_STATUS_REG_C	UCSR0C
   #define USART_ENABLE_TRANSMITTER		TXEN0
   #define USART_ENABLE_RECEIVER		RXEN0
   #define USART_READY_TO_TRANSMIT		UDRE0
   #define USART_TRANSMIT_COMPLETE		TXC0
   #define USART_RECEIVE_COMPLETE		RXC0
   #define USART_DATA_REG				UDR0
   #define USART_STOP_BIT_SELECT 		USBS0
   #define USART_CHARACTER_SIZE_0 		UCSZ0
   #define USART_CHARACTER_SIZE_1 		UCSZ1
   #define USART_REGISTER_SELECT		URSEL

#el*/
#if defined(ATmega32) || defined(Butterfly)

   // ATMega with one USART 
   #define USART_BAUD_RATE_HIGH        	UBRRH
   #define USART_BAUD_RATE_LOW        	UBRRL
   #define USART_CONTROL_STATUS_REG_A	UCSRA
   #define USART_CONTROL_STATUS_REG_B	UCSRB
   #define USART_CONTROL_STATUS_REG_C	UCSRC
   #define USART_ENABLE_TRANSMITTER		TXEN
   #define USART_ENABLE_RECEIVER		RXEN
   #define USART_READY_TO_TRANSMIT		UDRE
   #define USART_TRANSMIT_COMPLETE		TXC
   #define USART_RECEIVE_COMPLETE		RXC
   #define USART_DATA_REG				UDR
   #define USART_STOP_BIT_SELECT 		USBS
   #define USART_CHARACTER_SIZE_0 		UCSZ0
   #define USART_CHARACTER_SIZE_1 		UCSZ1
   #define USART_REGISTER_SELECT		URSEL

#elif defined(ATmega644) || defined(Arduino)

   // ATMega with two USARTs - USART 0
   #define USART_BAUD_RATE_HIGH			UBRR0H
   #define USART_BAUD_RATE_LOW			UBRR0L
   #define USART_CONTROL_STATUS_REG_A	UCSR0A
   #define USART_CONTROL_STATUS_REG_B	UCSR0B
   #define USART_CONTROL_STATUS_REG_C	UCSR0C
   #define USART_ENABLE_TRANSMITTER		TXEN0
   #define USART_ENABLE_RECEIVER		RXEN0
   #define USART_READY_TO_TRANSMIT		UDRE0
   #define USART_TRANSMIT_COMPLETE		TXC0
   #define USART_RECEIVE_COMPLETE		RXC0
   #define USART_DATA_REG				UDR0
   #define USART_STOP_BIT_SELECT		USBS0
   #define USART_CHARACTER_SIZE			UCSZ00

#else
   #error "no USART definition for MCU"
#endif

/*****************************************************
	USART function declarations	 
******************************************************/
static void Initialization();
static void USARTInit();
static void sendByte( uint8_t );
static uint8_t receiveByte( void );
void sendStringPROGMEM(const char *); 

#if defined(Butterfly)
void OSCCAL_calibration(void);
void Delay(unsigned int) ;
#endif


